package com.lwm.domain;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * 封装用户登录信息
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)// 告诉序列化器忽略未知的属性
// 上面的注解解决：org.springframework.data.redis.serializer.SerializationException:
// Could not read JSON: Unrecognized field "enabled" (class com.lwm.domain.LoginUser),
// not marked as ignorable (2 known properties: "authorities", "user"])
public class LoginUser implements UserDetails {

    private User user;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @Override
    public String getPassword() {
        return user.getPassword();
    }

    @Override
    public String getUsername() {
        return user.getUsername();
    }

    // true 账号未过期
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    // true 账号未锁定
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    // true 凭证未过期
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    // true 账号可用
    @Override
    public boolean isEnabled() {
        return true;
    }
}
